package com.gordon.tips.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.gordon.tips.dao.ReplyDao;
import com.gordon.tips.dao.TopicDao;
import com.gordon.tips.domain.Reply;
import com.gordon.tips.domain.Topic;
import com.gordon.tips.domain.User;
import com.gordon.tips.service.TopicService;

/**
 *****************************************************************************
 ** Module : Implementation of Topic control service
 ** 
 ** Date:  Aug 14, 2011
 ** 
 ** Author: Gordon
 ** 
 ** Email: 462991284@qq.com
 ** 
 ** (C) Copyright 2011 Gordon's Office
 *****************************************************************************
 */
public class TopicServiceImpl implements TopicService {
	
	private TopicDao topicDao;
	private ReplyDao replyDao;

	//function implementation
	@Transactional
	public List<Topic> getTopic(int start, int pageSize) {		
		return topicDao.getTopics(start, pageSize);
	}


	public void addNewTopic(Topic topic, Reply reply, User user) {
		topicDao.addNewTopic(topic, reply, user);
		
	}

	
	public void editTopic(Topic topic, Reply reply) {
		topicDao.editTopic(topic);
		replyDao.editReply(reply.getId(), reply.getContent());
	}
	
	//getter and setter
	public TopicDao getTopicDao() {
		return topicDao;
	}

	public void setTopicDao(TopicDao topicDao) {
		this.topicDao = topicDao;
	}

	
	public int countAllTopics() {		
		return topicDao.countAllTopics();
	}

	
	public Topic getTopicById(int id) {		
		return topicDao.getTopicById(id);
	}




	public ReplyDao getReplyDao() {
		return replyDao;
	}




	public void setReplyDao(ReplyDao replyDao) {
		this.replyDao = replyDao;
	}
	

}
